/**
 *
 *  封装组件Select
 * */
import React from 'react';
import { Select } from 'antd';
const Option = Select.Option;
class AntdSelect extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            dataSource: props.dataSource,
            defaultValue: props.defaultValue,
        }
    }
    componentWillReceiveProps(props) {
        this.setState({
            dataSource: props.dataSource,
            defaultValue: props.defaultValue,
        });
    }
    onChange(value){
        this.props.onChange(value);
    }

    render(){
        const listOptions = this.state.dataSource.map(item => <Option key={item.id}>{item.name}</Option>);

        if(this.state.dataSource){
            // console.log("select",this.state);
            return (
                <Select
                    defaultValue={this.state.defaultValue}
                    style={{ width: 120 }}
                    onChange={this.onChange.bind(this)}
                >
                    {listOptions}
                </Select>
            );
        }
        else {
            return (
                <span></span>
            )
        }
    }
}
export default AntdSelect;
